/**
 * 
 */
package commons;

/**
 * @author armstrong
 * 
 */
public class Preconditions {

	public static void check(final String errorMessage, final boolean value) {

		if (!value) {

			throw new IllegalArgumentException(errorMessage);
		}
	}

	/**
	 * @throws IllegalArgumentException
	 *             if number is negative.
	 */
	public static void checkIsNonNegative(final String errorMessage,
			final int number) {

		if (number < 0) {

			throw new IllegalArgumentException(errorMessage);
		}
	}

	/**
	 * @throws IllegalArgumentException
	 *             if number is not positive
	 */
	public static void checkIsPositive(final String errorMessage,
			final int number) {
		if (number <= 0) {

			throw new IllegalArgumentException(errorMessage);
		}
	}

	public static void checkIsValidPort(final String errorMessage,
			final int port) {

		if (port < 0 || port >= 0xFFFF) {

			throw new IllegalArgumentException(errorMessage);
		}
	}

	/**
	 * @throws IllegalArgumentException
	 *             if object is null.
	 */
	public static void checkNotNull(final String errorMessage,
			final Object object) {

		if (object == null) {

			throw new IllegalArgumentException(errorMessage);
		}
	}
}
